package com.example.emos.wx.common;

import com.example.emos.wx.exception.EnumResultMsg;
import com.example.emos.wx.exception.StatusResult;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

public class ResultVO<T> implements Serializable {
    private static final long serialVersionUID = 3037804830993369961L;
    protected String code;
    protected String msg;
    protected T data;
    public static final ResultVO<Void> OK;
    public static final ResultVO<Void> FAIL;

    public ResultVO(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ResultVO<Void> success(StatusResult result) {
        return new ResultVO(result.getCode(), result.getMsg());
    }

    public static <T> ResultVO<T> success(T data) {
        return success(EnumResultMsg.SUCCESS, data);
    }

    public static <T> ResultVO<T> success(StatusResult result, T data) {
        return new ResultVO(result.getCode(), result.getMsg(), data);
    }

    public static ResultVO<Void> error(StatusResult result) {
        return new ResultVO(result.getCode(), result.getMsg());
    }

    public static <T> ResultVO<T> error(StatusResult result, T data) {
        return new ResultVO(result.getCode(), result.getMsg(), data);
    }

    public String getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public T getData() {
        return this.data;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof ResultVO)) {
            return false;
        } else {
            ResultVO<?> other = (ResultVO)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label47: {
                    Object this$code = this.getCode();
                    Object other$code = other.getCode();
                    if (this$code == null) {
                        if (other$code == null) {
                            break label47;
                        }
                    } else if (this$code.equals(other$code)) {
                        break label47;
                    }

                    return false;
                }

                Object this$msg = this.getMsg();
                Object other$msg = other.getMsg();
                if (this$msg == null) {
                    if (other$msg != null) {
                        return false;
                    }
                } else if (!this$msg.equals(other$msg)) {
                    return false;
                }

                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof ResultVO;
    }

    public ResultVO() {
    }

    public ResultVO(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultVO(code=" + this.getCode() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ")";
    }

    static {
        OK = success((StatusResult)EnumResultMsg.SUCCESS);
        FAIL = error(EnumResultMsg.HTTP_STATUS_CODE_500);
    }
}
